/**
 * 
 */
package com.oolong.account.web;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.oolong.account.model.UserModel;
import com.oolong.account.service.StaticManage;
import com.oolong.account.vo.MonthStaticVo;

/**
 * @author oolong
 * 
 */
// 标记它是个SPRING的BEAN，是MVC里的C
@Controller
// 表示这个类就是staticmonthOutItem.do
@RequestMapping("/staticmonthItem.do")
public class StaticMonthController {
	Logger logger = Logger.getLogger(StaticMonthController.class);
	// 表示需要SPRING自动注入
	@Autowired
	private StaticManage staticManage;

	@RequestMapping(method = RequestMethod.GET)
	public String processOutItem(ModelMap model, HttpServletResponse response,
			HttpSession session) {
		UserModel userModel = (UserModel) session.getAttribute("user");
		int user_id = userModel.getId();
		List<MonthStaticVo> monthStaticVos = new ArrayList<MonthStaticVo>();
		// 当前月份
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH) + 1;
		String time = null;
		// 得到前面五个月
		for (int i = 0; i < 6; i++) {
			if (month < 10) {
				time = year + "0" + month;
			} else {
				time = year + "" + month;
			}
			monthStaticVos.add(staticManage
					.OneMonthStaticService(user_id, time));
			month = month - 1;
			if (month == 0) {
				month = 12;
				year = year - 1;
			}
		}
		model.addAttribute("monthStaticVos", monthStaticVos);
		response.setContentType("text/html;charset=UTF-8");
		return "staticmonth";
	}
}
